home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / buffer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-18  |  74.5 KB  |  2,252 lines

  1. /* Buffer manipulation primitives for XEmacs.
  2.    Copyright (C) 1985-1989, 1992-1994 Free Software Foundation, Inc.
  3.    Copyright (C) 1995 Sun Microsystems.
  4.  
  5. This file is part of XEmacs.
  6.  
  7. XEmacs is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with XEmacs; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* Synched up with: Mule 2.0, FSF 19.28. */
  22.  
  23. /* This file contains functions that work with buffer objects.
  24.    Functions that manipulate a buffer's text, however, are not
  25.    in this file:
  26.  
  27.    1) The low-level functions that actually know about the
  28.       implementation of a buffer's text are located in insdel.c.
  29.    2) The higher-level (mostly Lisp) functions that manipulate a
  30.       buffer's text are in editfns.c.
  31.    3) The highest-level Lisp commands are in cmds.c.
  32.  
  33.    However:
  34.  
  35.    -- Functions that know about syntax tables (forward-word,
  36.       scan-sexps, etc.) are in syntax.c, as are functions
  37.       that manipulate syntax tables.
  38.    -- Functions that know about case tables (upcase, downcase,
  39.       etc.) are in casefiddle.c.  Functions that manipulate
  40.       case tables (case-table-p, set-case-table, etc.) are
  41.       in casetab.c.
  42.    -- Functions that do searching and replacing are in
  43.       search.c.  The low-level functions that implement
  44.       regular expressions are in regex.c.
  45.  
  46.    Also:
  47.  
  48.    -- Some file and process functions (in fileio.c and process.c)
  49.       copy text from or insert text into a buffer; they call
  50.       low-level functions in insdel.c to do this.
  51.    -- insdel.c calls low-level functions in undo.c and extents.c
  52.       to record buffer modifications for undoing and to handle
  53.       extent adjustment and extent-data creation and insertion.
  54.  
  55. */
  56.  
  57. #include <config.h>
  58. #include "lisp.h"
  59.  
  60. #include "buffer.h"
  61. #include "commands.h"
  62. #include "extents.h"
  63. #include "faces.h"
  64. #include "frame.h"
  65. #include "insdel.h"
  66. #include "process.h"            /* for kill_buffer_processes */
  67. #include "symeval.h"
  68. #include "syntax.h"
  69. #include "sysdep.h"    /* for getwd */
  70. #include "window.h"
  71.  
  72. #include "sysfile.h"
  73.  
  74. struct buffer *current_buffer;    /* the current buffer */
  75.  
  76. /* This structure holds the default values of the buffer-local variables
  77.    defined with DEFVAR_BUFFER_LOCAL, that have special slots in each buffer.
  78.    The default value occupies the same slot in this structure
  79.    as an individual buffer's value occupies in that buffer.
  80.    Setting the default value also goes through the alist of buffers
  81.    and stores into each buffer that does not say it has a local value.  */
  82. Lisp_Object Vbuffer_defaults;
  83.  
  84. /* This structure marks which slots in a buffer have corresponding
  85.    default values in buffer_defaults.
  86.    Each such slot has a nonzero value in this structure.
  87.    The value has only one nonzero bit.
  88.  
  89.    When a buffer has its own local value for a slot,
  90.    the bit for that slot (found in the same slot in this structure)
  91.    is turned on in the buffer's local_var_flags slot.
  92.  
  93.    If a slot in this structure is 0, then there is a DEFVAR_BUFFER_LOCAL
  94.    for the slot, but there is no default value for it; the corresponding
  95.    slot in buffer_defaults is not used except to initialize newly-created
  96.    buffers.
  97.  
  98.    If a slot is -1, then there is a DEFVAR_BUFFER_LOCAL for it
  99.    as well as a default value which is used to initialize newly-created
  100.    buffers and as a reset-value when local-vars are killed.
  101.  
  102.    If a slot is -2, there is no DEFVAR_BUFFER_LOCAL for it. 
  103.    (The slot is always local, but there's no lisp variable for it.)
  104.    The default value is only used to initialize newly-creation buffers. 
  105.    
  106.    If a slot is -3, then there is no DEFVAR_BUFFER_LOCAL for it but
  107.    there is a default which is used to initialize newly-creation
  108.    buffers and as a reset-value when local-vars are killed.
  109.  
  110.    
  111.    */
  112. struct buffer buffer_local_flags;
  113.  
  114. /* This structure holds the names of symbols whose values may be
  115.    buffer-local.  It is indexed and accessed in the same way as the above. */
  116. static Lisp_Object Vbuffer_local_symbols;
  117.  
  118. /* Alist of all buffer names vs the buffers. */
  119. /* This used to be a variable, but is no longer,
  120.    to prevent lossage due to user rplac'ing this alist or its elements.
  121.    Note that there is a per-frame copy of this as well; the frame slot
  122.    and the global variable contain the same data, but possibly in different
  123.    orders, so that the buffer ordering can be per-frame.
  124.   */
  125. Lisp_Object Vbuffer_alist;
  126.  
  127. /* Functions to call before and after each text change. */
  128. Lisp_Object Qbefore_change_functions;
  129. Lisp_Object Qafter_change_functions;
  130. Lisp_Object Vbefore_change_functions;
  131. Lisp_Object Vafter_change_functions;
  132.  
  133. /* #### Obsolete, for compatibility */
  134. Lisp_Object Qbefore_change_function;
  135. Lisp_Object Qafter_change_function;
  136. Lisp_Object Vbefore_change_function;
  137. Lisp_Object Vafter_change_function;
  138.  
  139. #if 0 /* FSFmacs */
  140. Lisp_Object Vtransient_mark_mode;
  141. #endif
  142.  
  143. /* t means ignore all read-only text properties.
  144.    A list means ignore such a property if its value is a member of the list.
  145.    Any non-nil value means ignore buffer-read-only.  */
  146. Lisp_Object Vinhibit_read_only;
  147.  
  148. /* List of functions to call that can query about killing a buffer.
  149.    If any of these functions returns nil, we don't kill it.  */
  150. Lisp_Object Vkill_buffer_query_functions;
  151.  
  152. /* Non-nil means delete a buffer's auto-save file when the buffer is saved. */
  153. Lisp_Object Vdelete_auto_save_files;
  154.  
  155. Lisp_Object Qbuffer_live_p;
  156. Lisp_Object Qbuffer_or_string_p;
  157.  
  158. /* List of functions to call before changing an unmodified buffer.  */
  159. Lisp_Object Vfirst_change_hook;
  160. Lisp_Object Qfirst_change_hook;
  161.  
  162. Lisp_Object Qfundamental_mode;
  163. Lisp_Object Qmode_class;
  164. Lisp_Object Qpermanent_local;
  165.  
  166. Lisp_Object Qprotected_field;
  167.  
  168. Lisp_Object QSFundamental;    /* A string "Fundamental" */
  169. Lisp_Object QSscratch;          /* "*scratch*" */
  170. Lisp_Object Qdefault_directory;
  171.  
  172. Lisp_Object Qkill_buffer_hook;
  173. Lisp_Object Qbuffer_file_name, Qbuffer_undo_list;
  174.  
  175. Lisp_Object Qrename_auto_save_file;
  176.  
  177. Lisp_Object Qget_file_buffer;
  178. Lisp_Object Qchange_major_mode_hook, Vchange_major_mode_hook;
  179.  
  180. /* Two thresholds controlling how much undo information to keep.  */
  181. int undo_threshold;
  182. int undo_high_threshold;
  183.  
  184. int find_file_compare_truenames;
  185. int find_file_use_truenames;
  186.  
  187.  
  188. static void reset_buffer_local_variables (struct buffer *);
  189. static Lisp_Object mark_buffer (Lisp_Object, void (*) (Lisp_Object));
  190. static void print_buffer (Lisp_Object, Lisp_Object, int);
  191. DEFINE_LRECORD_IMPLEMENTATION ("buffer", buffer,
  192.                                mark_buffer, print_buffer, 0, 0, 0,
  193.                    struct buffer);
  194.  
  195. #ifdef ENERGIZE
  196. extern void mark_energize_buffer_data (struct buffer *b,
  197.                        void (*markobj) (Lisp_Object));
  198. #endif
  199.  
  200. Lisp_Object
  201. make_buffer (struct buffer *buf)
  202. {
  203.   Lisp_Object obj;
  204.   XSETBUFFER (obj, buf);
  205.   return obj;
  206. }
  207.  
  208. static Lisp_Object
  209. mark_buffer (Lisp_Object obj, void (*markobj) (Lisp_Object))
  210. {
  211.   struct buffer *buf = XBUFFER (obj);
  212.  
  213.   /* Truncate undo information. */
  214.   buf->undo_list = truncate_undo_list (buf->undo_list,
  215.                                        undo_threshold,
  216.                                        undo_high_threshold);
  217.  
  218. #define MARKED_SLOT(x) ((markobj) (buf->x));
  219. #include "bufslots.h"
  220. #undef MARKED_SLOT
  221.  
  222.   mark_buffer_extents (buf, markobj);
  223.  
  224. #ifdef ENERGIZE
  225.   mark_energize_buffer_data (XBUFFER (obj), markobj);
  226. #endif
  227.  
  228.   return (Qnil);
  229. }
  230.  
  231. static void
  232. print_buffer (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
  233. {
  234.   struct buffer *b = XBUFFER (obj);
  235.  
  236.   if (print_readably) 
  237.     {
  238.       if (!BUFFER_LIVE_P (b))
  239.     error ("printing unreadable object #<killed buffer>");
  240.       else
  241.     error ("printing unreadable object #<buffer %s>", 
  242.            string_data (XSTRING (b->name)));
  243.     }
  244.   else if (!BUFFER_LIVE_P (b))
  245.     write_c_string ("#<killed buffer>", printcharfun);
  246.   else if (escapeflag)
  247.     {
  248.       write_c_string ("#<buffer ", printcharfun);
  249.       print_internal (b->name, printcharfun, 1);
  250.       write_c_string (">", printcharfun);
  251.     }
  252.   else
  253.     {
  254.       print_internal (b->name, printcharfun, 0);
  255.     }
  256. }
  257.    
  258.   
  259.  
  260. DEFUN ("bufferp", Fbufferp, Sbufferp, 1, 1, 0,
  261.   "T if OBJECT is an editor buffer.")
  262.   (object)
  263.      Lisp_Object object;
  264. {
  265.   if (BUFFERP (object))
  266.     return Qt;
  267.   return Qnil;
  268. }
  269.  
  270. DEFUN ("buffer-live-p", Fbuffer_live_p, Sbuffer_live_p, 1, 1, 0,
  271.   "T if OBJECT is an editor buffer that has not been deleted.")
  272.   (object)
  273.      Lisp_Object object;
  274. {
  275.   if (BUFFERP (object) && BUFFER_LIVE_P (XBUFFER (object)))
  276.     return Qt;
  277.   return Qnil;
  278. }
  279.  
  280. static void
  281. nsberror (Lisp_Object spec)
  282. {
  283.   if (STRINGP (spec))
  284.     error ("No buffer named %s", string_data (XSTRING (spec)));
  285.   signal_simple_error ("Invalid buffer argument", spec);
  286. }
  287.  
  288. DEFUN ("buffer-list", Fbuffer_list, Sbuffer_list, 0, 1, 0,
  289.   "Return a list of all existing live buffers.\n\
  290. The order is specific to the selected frame; if the optional FRAME\n\
  291. argument is provided, the ordering for that frame is returned instead.\n\
  292. If the FRAME argument is t, then the global (non-frame) ordering is\n\
  293. returned instead.")
  294.   (frame)
  295.   Lisp_Object frame;
  296. {
  297.   Lisp_Object list;
  298.   if (EQ (frame, Qt))
  299.     list = Vbuffer_alist;
  300.   else
  301.     list = get_frame (frame)->buffer_alist;
  302.   return Fmapcar (Qcdr, list);
  303. }
  304.  
  305. Lisp_Object
  306. get_buffer (Lisp_Object name, int error_if_deleted_or_does_not_exist)
  307. {
  308.   Lisp_Object buf;
  309.  
  310.   if (BUFFERP (name))
  311.     {
  312.       if (!BUFFER_LIVE_P (XBUFFER (name)))
  313.         {
  314.           if (error_if_deleted_or_does_not_exist)
  315.             nsberror (name);
  316.           return (Qnil);
  317.         }
  318.       return name;
  319.     }
  320.   else
  321.     {
  322.       struct gcpro gcpro1;
  323.  
  324.       CHECK_STRING (name, 0);
  325.       name = LISP_GETTEXT (name); /* I18N3 */
  326.       GCPRO1 (name);
  327.       buf = Fcdr (Fassoc (name, Vbuffer_alist));
  328.       UNGCPRO;
  329.       if (NILP (buf) && error_if_deleted_or_does_not_exist)
  330.     nsberror (name);
  331.       return (buf);
  332.     }
  333. }
  334.  
  335. struct buffer *
  336. decode_buffer (Lisp_Object buffer, int allow_string)
  337. {
  338.   if (NILP (buffer))
  339.     {
  340.       return current_buffer;
  341.     }
  342.   else if (STRINGP (buffer))
  343.     {
  344.       if (allow_string)
  345.     return XBUFFER (get_buffer (buffer, 1));
  346.       else
  347.     CHECK_BUFFER (buffer, 0);    /* This will cause a wrong-type error. */
  348.     }
  349.  
  350.   CHECK_LIVE_BUFFER (buffer, 0);
  351.   return XBUFFER (buffer);
  352. }
  353.  
  354. DEFUN ("decode-buffer", Fdecode_buffer, Sdecode_buffer, 1, 1, 0,
  355.   "Validate BUFFER or if BUFFER is nil, return the current buffer.\n\
  356. If BUFFER is a valid buffer or a string representing a valid buffer,\n\
  357. the corresponding buffer object will be returned.  Otherwise an error\n\
  358. will be signaled.")
  359.   (buffer)
  360.   Lisp_Object buffer;
  361. {
  362.   struct buffer *b = decode_buffer (buffer, 1);
  363.   XSETBUFFER (buffer, b);
  364.   return buffer;
  365. }
  366.  
  367. DEFUN ("get-buffer", Fget_buffer, Sget_buffer, 1, 1, 0,
  368.   "Return the buffer named NAME (a string).\n\
  369. If there is no live buffer named NAME, return nil.\n\
  370. NAME may also be a buffer; if so, the value is that buffer.")
  371.   (name)
  372.      Lisp_Object name;
  373. {
  374. #ifdef I18N3
  375.   /* #### Doc string should indicate that the buffer name will get
  376.      translated. */
  377. #endif
  378.  
  379.   /* #### This might return a dead buffer.  This is gross.  This is
  380.      called FSF compatibility. */
  381.   if (BUFFERP (name))
  382.     return name;
  383.   return (get_buffer (name, 0));
  384. }
  385.  
  386.  
  387. DEFUN ("get-file-buffer", Fget_file_buffer, Sget_file_buffer, 1, 1, 0,
  388.   "Return the buffer visiting file FILENAME (a string).\n\
  389. If there is no such live buffer, return nil.")
  390.   (filename)
  391.      Lisp_Object filename;
  392. {
  393.   /* This function can GC */
  394.   REGISTER Lisp_Object tail, buf, tem;
  395.   struct gcpro gcpro1;
  396.  
  397. #ifdef I18N3
  398.   /* DO NOT translate the filename. */
  399. #endif
  400.   GCPRO1 (filename);
  401.   CHECK_STRING (filename, 0);
  402.   filename = Fexpand_file_name (filename, Qnil);
  403.   {
  404.     /* If the file name has special constructs in it,
  405.        call the corresponding file handler.  */
  406.     Lisp_Object handler = Ffind_file_name_handler (filename, Qget_file_buffer);
  407.     if (!NILP (handler))
  408.       {
  409.     UNGCPRO;
  410.     return call2 (handler, Qget_file_buffer, filename);
  411.       }
  412.   }
  413.   UNGCPRO;
  414.  
  415.   if (find_file_compare_truenames || find_file_use_truenames)
  416.     {
  417.       struct gcpro gcpro1, gcpro2, gcpro3;
  418.       Lisp_Object fn = Qnil;
  419.       Lisp_Object dn = Qnil;
  420.  
  421.       GCPRO3 (fn, dn, filename);
  422.       fn = Ffile_truename (filename, Qnil);
  423.       if (NILP (fn))
  424.     {
  425.       dn = Ffile_name_directory (filename);
  426.       fn = Ffile_truename (dn, Qnil);
  427.       if (! NILP (fn)) dn = fn;
  428.       fn = Fexpand_file_name (Ffile_name_nondirectory (filename),
  429.                   dn);
  430.     }
  431.       filename = fn;
  432.       UNGCPRO;
  433.     }
  434.  
  435.   for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
  436.     {
  437.       buf = Fcdr (XCAR (tail));
  438.       if (!BUFFERP (buf)) continue;
  439.       if (!STRINGP (XBUFFER (buf)->filename)) continue;
  440.       tem = Fstring_equal (filename,
  441.                (find_file_compare_truenames
  442.                 ? XBUFFER (buf)->truename
  443.                 : XBUFFER (buf)->filename));
  444.       if (!NILP (tem))
  445.     return buf;
  446.     }
  447.   return Qnil;
  448. }
  449.  
  450.  
  451. static void
  452. push_buffer_alist (Lisp_Object name, Lisp_Object buf)
  453. {
  454.   Lisp_Object cons = Fcons (name, buf);
  455.   Lisp_Object rest, dev;
  456.   Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (cons, Qnil));
  457.   DEVICE_AND_FRAME_LOOP (dev, rest)
  458.     {
  459.       struct frame *f;
  460.       f = XFRAME (XCAR (rest));
  461.       f->buffer_alist = nconc2 (f->buffer_alist, Fcons (cons, Qnil));
  462.     }
  463. }
  464.  
  465. static void
  466. delete_from_buffer_alist (Lisp_Object buf)
  467. {
  468.   Lisp_Object cons = Frassq (buf, Vbuffer_alist);
  469.   Lisp_Object rest, dev;
  470.   if (NILP (cons))
  471.     return; /* abort() ? */
  472.   Vbuffer_alist = delq_no_quit (cons, Vbuffer_alist);
  473.   DEVICE_AND_FRAME_LOOP (dev, rest)
  474.     {
  475.       struct frame *f;
  476.       f = XFRAME (XCAR (rest));
  477.       f->buffer_alist = delq_no_quit (cons, f->buffer_alist);
  478.     }
  479. }
  480.  
  481.  
  482. DEFUN ("get-buffer-create", Fget_buffer_create, Sget_buffer_create, 1, 1, 0,
  483.   "Return the buffer named NAME, or create such a buffer and return it.\n\
  484. A new buffer is created if there is no live buffer named NAME.\n\
  485. If NAME starts with a space, the new buffer does not keep undo information.\n\
  486. If NAME is a buffer instead of a string, then it is the value returned.\n\
  487. The value is never nil.")  
  488.   (name)
  489.      Lisp_Object name;
  490. {
  491.   /* This function can GC */
  492.   Lisp_Object buf;
  493.   REGISTER Lisp_Object function, tem;
  494.   int speccount = specpdl_depth ();
  495.   REGISTER struct buffer *b;
  496.  
  497. #ifdef I18N3
  498.   /* #### Doc string should indicate that the buffer name will get
  499.      translated. */
  500. #endif
  501.  
  502.   name = LISP_GETTEXT (name);
  503.   buf = Fget_buffer (name);
  504.   if (!NILP (buf))
  505.     return buf;
  506.  
  507.   if (string_length (XSTRING (name)) == 0)
  508.     error ("Empty string for buffer name is not allowed");
  509.  
  510.   b = alloc_lcrecord (sizeof (struct buffer), lrecord_buffer);
  511.   XSETBUFFER (buf, b);
  512.   {
  513.     /* Default everything to Vbuffer_defaults,
  514.        remembering to preserve allocation/GC info */
  515.     struct lcrecord_header save;
  516.     save = b->header;
  517.     *b = *XBUFFER (Vbuffer_defaults);
  518.     b->header = save;
  519.   }
  520.   reset_buffer_local_variables (b);
  521.   b->directory = ((current_buffer) ? current_buffer->directory : Qnil);
  522.  
  523.   init_buffer_text (b);
  524.   BUF_MODIFF (b) = 1;
  525.   BUF_FACECHANGE (b) = 1;
  526.  
  527.   b->last_window_start = 1;
  528.  
  529.   b->name = name;
  530.   if (string_byte (XSTRING (name), 0) != ' ')
  531.     b->undo_list = Qnil;
  532.   else
  533.     b->undo_list = Qt;
  534.  
  535.   /* initialize the extent list */
  536.   init_buffer_extents (b);
  537.  
  538.   /* Put this in the alist of all live buffers.  */
  539.   push_buffer_alist (name, buf);
  540.  
  541.   b->mark = Fmake_marker ();
  542.   b->markers = 0;
  543.   b->point_marker = Fmake_marker ();
  544.   Fset_marker (b->point_marker, make_number (1), buf);
  545.  
  546.   function = XBUFFER (Vbuffer_defaults)->major_mode;
  547.   if (NILP (function))
  548.     {
  549.       tem = Fget (current_buffer->major_mode, Qmode_class, Qnil);
  550.       if (EQ (tem, Qnil))
  551.     function = current_buffer->major_mode;
  552.     }
  553.  
  554.   if (NILP (function) || EQ (function, Qfundamental_mode))
  555.     return buf;
  556.  
  557.   /* To select a nonfundamental mode,
  558.      select the buffer temporarily and then call the mode function. */
  559.  
  560.   record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
  561.  
  562.   Fset_buffer (buf);
  563.   call0 (function);
  564.  
  565.   return unbind_to (speccount, buf);
  566. }
  567.  
  568.  
  569. static void
  570. reset_buffer_local_variables (struct buffer *b)
  571. {
  572.   struct buffer *def = XBUFFER (Vbuffer_defaults);
  573.  
  574.   b->local_var_flags = 0;
  575.   /* For each slot that has a default value,
  576.      copy that into the slot.  */
  577. #define MARKED_SLOT(slot) \
  578.   { int mask = XINT (buffer_local_flags.slot); \
  579.     if (mask > 0 || mask == -1 || mask == -3) \
  580.       b->slot = def->slot; \
  581.   }
  582. #include "bufslots.h"
  583. #undef MARKED_SLOT
  584. }
  585.  
  586.  
  587. /* We split this away from generate-new-buffer, because rename-buffer
  588.    and set-visited-file-name ought to be able to use this to really
  589.    rename the buffer properly.  */
  590.  
  591. DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name, Sgenerate_new_buffer_name,
  592.   1, 2, 0,
  593.   "Return a string that is the name of no existing buffer based on NAME.\n\
  594. If there is no live buffer named NAME, then return NAME.\n\
  595. Otherwise modify name by appending `<NUMBER>', incrementing NUMBER\n\
  596. until an unused name is found, and then return that name.\n\
  597. Optional second argument IGNORE specifies a name that is okay to use\n\
  598. \(if it is in the sequence to be tried)\n\
  599. even if a buffer with that name exists.")
  600.  (name, ignore)
  601.      Lisp_Object name, ignore;
  602. {
  603.   REGISTER Lisp_Object gentemp, tem;
  604.   int count;
  605.   char number[10];
  606.  
  607.   CHECK_STRING (name, 0);
  608.  
  609.   name = LISP_GETTEXT (name);
  610. #ifdef I18N3
  611.   /* #### Doc string should indicate that the buffer name will get
  612.      translated. */
  613. #endif
  614.  
  615.   tem = Fget_buffer (name);
  616.   if (NILP (tem))
  617.     return (name);
  618.  
  619.   count = 1;
  620.   while (1)
  621.     {
  622.       sprintf (number, "<%d>", ++count);
  623.       gentemp = concat2 (name, build_string (number));
  624.       if (!NILP (ignore))
  625.         {
  626.           tem = Fstring_equal (gentemp, ignore);
  627.           if (!NILP (tem))
  628.             return gentemp;
  629.         }
  630.       tem = Fget_buffer (gentemp);
  631.       if (NILP (tem))
  632.     return (gentemp);
  633.     }
  634. }
  635.  
  636.  
  637. DEFUN ("buffer-name", Fbuffer_name, Sbuffer_name, 0, 1, 0,
  638.   "Return the name of BUFFER, as a string.\n\
  639. With no argument or nil as argument, return the name of the current buffer.")
  640.   (buffer)
  641.      Lisp_Object buffer;
  642. {
  643.   if (NILP (buffer))
  644.     return current_buffer->name;
  645.   CHECK_BUFFER (buffer, 0);
  646.   return XBUFFER (buffer)->name;
  647. }
  648.  
  649. DEFUN ("buffer-file-name", Fbuffer_file_name, Sbuffer_file_name, 0, 1, 0,
  650.   "Return name of file BUFFER is visiting, or nil if none.\n\
  651. No argument or nil as argument means use the current buffer.")
  652.   (buffer)
  653.      Lisp_Object buffer;
  654. {
  655.   if (NILP (buffer))
  656.     return current_buffer->filename;
  657.   CHECK_BUFFER (buffer, 0);
  658.   return XBUFFER (buffer)->filename;
  659. }
  660.  
  661. DEFUN ("buffer-local-variables", Fbuffer_local_variables,
  662.   Sbuffer_local_variables, 0, 1, 0,
  663.   "Return an alist of variables that are buffer-local in BUFFER.\n\
  664. Most elements look like (SYMBOL . VALUE), describing one variable.\n\
  665. For a symbol that is locally unbound, just the symbol appears in the value.\n\
  666. Note that storing new VALUEs in these elements doesn't change the variables.\n\
  667. No argument or nil as argument means use current buffer as BUFFER.")
  668.   (buffer)
  669.      Lisp_Object buffer;
  670. {
  671.   struct buffer *buf = decode_buffer (buffer, 0);
  672.   Lisp_Object result = Qnil;
  673.  
  674.   {
  675.     /* Reference each variable in the alist in our current buffer.
  676.        If inquiring about the current buffer, this gets the current values,
  677.        so store them into the alist so the alist is up to date.
  678.        If inquiring about some other buffer, this swaps out any values
  679.        for that buffer, making the alist up to date automatically.  */
  680.     Lisp_Object tail;
  681.     for (tail = buf->local_var_alist; CONSP (tail); tail = XCDR (tail))
  682.       {
  683.         Lisp_Object elt = XCAR (tail);
  684.         Lisp_Object val = ((buf == current_buffer)
  685.                            ? find_symbol_value (XCAR (elt))
  686.                            : XCDR (elt));
  687.  
  688.     /* If symbol is unbound, put just the symbol in the list.  */
  689.     if (EQ (val, Qunbound))
  690.       result = Fcons (XCAR (elt), result);
  691.     /* Otherwise, put (symbol . value) in the list.  */
  692.     else
  693.       result = Fcons (Fcons (XCAR (elt), val), result);
  694.       }
  695.   }
  696.  
  697.   /* Add on all the variables stored in special slots.  */
  698.   {
  699.     struct buffer *syms = XBUFFER (Vbuffer_local_symbols);
  700. #define MARKED_SLOT(slot) \
  701.     { int mask = XINT (buffer_local_flags.slot); \
  702.       if (mask == 0 || mask == -1 \
  703.       || ((mask > 0) && (buf->local_var_flags & mask))) \
  704.         result = Fcons (Fcons (syms->slot, buf->slot), result); \
  705.     }
  706. #include "bufslots.h"
  707. #undef MARKED_SLOT
  708.   }
  709.   return (result);
  710. }
  711.  
  712. DEFUN ("buffer-dedicated-frame", Fbuffer_dedicated_frame, Sbuffer_dedicated_frame,
  713.        0, 1, 0,
  714.        "Return the frame dedicated to this BUFFER, or nil if there is none.\n\
  715. No argument or nil as argument means use current buffer as BUFFER.")
  716.   (buffer)
  717.      Lisp_Object buffer;
  718. {
  719.   struct buffer *buf = decode_buffer (buffer, 0);
  720.  
  721.   /* XEmacs addition: if the frame is dead, silently make it go away. */
  722.   if (!NILP (buf->dedicated_frame) &&
  723.       !FRAME_LIVE_P (XFRAME (buf->dedicated_frame)))
  724.     buf->dedicated_frame = Qnil;
  725.     
  726.   return buf->dedicated_frame;
  727. }
  728.  
  729. DEFUN ("set-buffer-dedicated-frame", Fset_buffer_dedicated_frame,
  730.        Sset_buffer_dedicated_frame,
  731.        2, 2, 0,
  732.        "For this BUFFER, set the FRAME dedicated to it.\n\
  733. FRAME must be a frame or nil.")
  734.   (buffer, frame)
  735.      Lisp_Object buffer, frame;
  736. {
  737.   struct buffer *buf = decode_buffer (buffer, 0);
  738.  
  739.   if (!NILP (frame))
  740.     CHECK_LIVE_FRAME (frame, 0); /* XEmacs change */
  741.  
  742.   return buf->dedicated_frame = frame;
  743. }
  744.  
  745.  
  746.  
  747. DEFUN ("buffer-modified-p", Fbuffer_modified_p, Sbuffer_modified_p,
  748.   0, 1, 0,
  749.   "Return t if BUFFER was modified since its file was last read or saved.\n\
  750. No argument or nil as argument means use current buffer as BUFFER.")
  751.   (buffer)
  752.      Lisp_Object buffer;
  753. {
  754.   struct buffer *buf = decode_buffer (buffer, 0);
  755.  
  756.   return buf->save_modified < BUF_MODIFF (buf) ? Qt : Qnil;
  757. }
  758.  
  759. DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p, Sset_buffer_modified_p,
  760.   1, 2, 0,
  761.   "Mark BUFFER as modified or unmodified according to FLAG.\n\
  762. A non-nil FLAG means mark the buffer modified.  No argument or nil\n\
  763. as BUFFER means use current buffer.")
  764.   (flag, buffer)
  765.      Lisp_Object flag, buffer;
  766. {
  767.   /* This function can GC */
  768.   Lisp_Object fn;
  769.   struct buffer *buf = decode_buffer (buffer, 0);
  770.  
  771. #ifdef ENERGIZE
  772.   Lisp_Object starting_flag = 
  773.     (buf->save_modified < BUF_MODIFF (buf)) ? Qt : Qnil;
  774.   Lisp_Object argument_flag = (NILP (flag)) ? Qnil : Qt;
  775. #endif  
  776.  
  777. #ifdef CLASH_DETECTION
  778.   /* If buffer becoming modified, lock the file.
  779.      If buffer becoming unmodified, unlock the file.  */
  780.  
  781.   fn = buf->filename;
  782.   if (!NILP (fn))
  783.     {
  784.       int already = buf->save_modified < BUF_MODIFF (buf);
  785.       if (already == NILP (flag))
  786.     {
  787.       int count = specpdl_depth ();
  788.       /* lock_file() and unlock_file() currently use current_buffer */
  789.       record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
  790.       set_buffer_internal (buf);
  791.       if (!already && !NILP (flag))
  792.         lock_file (fn);
  793.       else if (already && NILP (flag))
  794.         unlock_file (fn);
  795.       unbind_to (count, Qnil);
  796.     }
  797.     }
  798. #endif                          /* CLASH_DETECTION */
  799.  
  800.   /* This is often called when the buffer contents are altered but we
  801.      don't want to treat the changes that way (e.g. selective
  802.      display).  We still need to make sure redisplay realizes that the
  803.      contents have potentially altered and it needs to do some
  804.      work. */
  805.   BUF_MODIFF (buf)++;
  806.   buf->save_modified = NILP (flag) ? BUF_MODIFF (buf) : 0;
  807.   MARK_MODELINE_CHANGED;
  808.  
  809. #ifdef ENERGIZE
  810.   /* don't send any notification if we are "setting" the modification bit
  811.      to be the same as it already was */
  812.   if (!EQ (starting_flag, argument_flag))
  813.     {
  814.       extern Lisp_Object Qenergize_buffer_modified_hook;
  815.       int count = specpdl_depth ();
  816.       record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
  817.       set_buffer_internal (buf);
  818.       run_hook_with_args (Qenergize_buffer_modified_hook, 3,
  819.               flag, make_number (BUF_BEG (buf)),
  820.               make_number (BUF_Z (buf)));
  821.       unbind_to (count, Qnil);
  822.     }
  823. #endif /* ENERGIZE */
  824.  
  825.   return flag;
  826. }
  827.  
  828. DEFUN ("buffer-modified-tick", Fbuffer_modified_tick, Sbuffer_modified_tick,
  829.   0, 1, 0,
  830.   "Return BUFFER's tick counter, incremented for each change in text.\n\
  831. Each buffer has a tick counter which is incremented each time the text in\n\
  832. that buffer is changed.  It wraps around occasionally.\n\
  833. No argument or nil as argument means use current buffer as BUFFER.")
  834.   (buffer)
  835.      Lisp_Object buffer;
  836. {
  837.   struct buffer *buf = decode_buffer (buffer, 0);
  838.  
  839.   return make_number (BUF_MODIFF (buf));
  840. }
  841.  
  842. DEFUN ("rename-buffer", Frename_buffer, Srename_buffer, 1, 2,
  843.        "sRename buffer (to new name): \nP",
  844.   "Change current buffer's name to NAME (a string).\n\
  845. If second arg UNIQUE is nil or omitted, it is an error if a\n\
  846. buffer named NAME already exists.\n\
  847. If UNIQUE is non-nil, come up with a new name using\n\
  848. `generate-new-buffer-name'.\n\
  849. Interactively, one can set UNIQUE with a prefix argument.\n\
  850. Returns the name we actually gave the buffer.\n\
  851. This does not change the name of the visited file (if any).")
  852.   (name, unique)
  853.      Lisp_Object name, unique;
  854. {
  855.   /* This function can GC */
  856.   Lisp_Object tem, buf;
  857.  
  858. #ifdef I18N3
  859.   /* #### Doc string should indicate that the buffer name will get
  860.      translated. */
  861. #endif
  862.   CHECK_STRING (name, 0);
  863.   name = LISP_GETTEXT (name);
  864.  
  865.   if (string_length (XSTRING (name)) == 0)
  866.     error ("Empty string is invalid as a buffer name");
  867.  
  868.   tem = Fget_buffer (name);
  869.   /* Don't short-circuit if UNIQUE is t.  That is a useful way to rename
  870.      the buffer automatically so you can create another with the original name.
  871.      It makes UNIQUE equivalent to
  872.      (rename-buffer (generate-new-buffer-name NAME)).  */
  873.   /* XEmacs change: added check for nil */
  874.   if (NILP (unique) && !NILP (tem) && XBUFFER (tem) == current_buffer)
  875.     return current_buffer->name;
  876.   if (!NILP (tem))
  877.     {
  878.       if (!NILP (unique))
  879.     name = Fgenerate_new_buffer_name (name, current_buffer->name);
  880.       else
  881.     error ("Buffer name \"%s\" is in use",
  882.            string_data (XSTRING (name)));
  883.     }
  884.  
  885.   current_buffer->name = name;
  886.  
  887.   /* Catch redisplay's attention.  Unless we do this, the modelines for
  888.      any windows displaying current_buffer will stay unchanged.  */
  889.   MARK_MODELINE_CHANGED;
  890.  
  891.   buf = Fcurrent_buffer ();
  892.  
  893.   /* The aconses in the Vbuffer_alist are shared with frame->buffer_alist,
  894.      so this will change it in the per-frame ordering as well. */
  895.   Fsetcar (Frassq (buf, Vbuffer_alist), name);
  896.   if (NILP (current_buffer->filename)
  897.       && !NILP (current_buffer->auto_save_file_name))
  898.     call0 (Qrename_auto_save_file);
  899.   /* refetch since that last call may have done GC */
  900.   /* (hypothetical relocating GC) */
  901.   return current_buffer->name;
  902. }
  903.  
  904. DEFUN ("other-buffer", Fother_buffer, Sother_buffer, 0, 3, 0,
  905.   "Return most recently selected buffer other than BUFFER.\n\
  906. Buffers not visible in windows are preferred to visible buffers,\n\
  907. unless optional third argument VISIBLE-OK is non-nil.\n\
  908. If no other buffer exists, the buffer `*scratch*' is returned.\n\
  909. If BUFFER is omitted or nil, some interesting buffer is returned.\n\
  910. \n\
  911. The ordering is for this frame; If second optional argument FRAME\n\
  912. is provided, then the ordering is for that frame.  If the second arg\n\
  913. is t, then the global ordering is returned.\n\
  914. \n\
  915. Note: In FSF Emacs, this function takes two arguments: BUFFER and\n\
  916. VISIBLE-OK.")
  917.   (buffer, frame, visible_ok)
  918.      Lisp_Object buffer, frame, visible_ok;
  919. {
  920.   /* This function can GC */
  921.   Lisp_Object tail, buf, notsogood, tem;
  922.   Lisp_Object alist;
  923.  
  924.   notsogood = Qnil;
  925.  
  926.   if (EQ (frame, Qt))
  927.     alist = Vbuffer_alist;
  928.   else
  929.     alist = get_frame (frame)->buffer_alist;
  930.  
  931.   for (tail = alist; !NILP (tail); tail = Fcdr (tail))
  932.     {
  933.       buf = Fcdr (Fcar (tail));
  934.       if (EQ (buf, buffer))
  935.     continue;
  936.       if (string_byte (XSTRING (XBUFFER (buf)->name), 0) == ' ')
  937.     continue;
  938.       if (NILP (visible_ok))
  939.     {
  940.       /* get-buffer-window will handle nil or t frame */
  941.       tem = Fget_buffer_window (buf, frame, Qnil);
  942.     }
  943.       else
  944.     tem = Qnil;
  945.       if (NILP (tem))
  946.     return buf;
  947.       if (NILP (notsogood))
  948.     notsogood = buf;
  949.     }
  950.   if (!NILP (notsogood))
  951.     return notsogood;
  952.   return Fget_buffer_create (QSscratch);
  953. }
  954.  
  955. /* XEmacs change: Make this argument required because this is a dangerous
  956.    function. */
  957. DEFUN ("buffer-disable-undo", Fbuffer_disable_undo, Sbuffer_disable_undo, 1, 1, 0,
  958.   "Make BUFFER stop keeping undo information.\n\
  959. Any undo records it already has are discarded.")
  960.   (buffer)
  961.      Lisp_Object buffer;
  962. {
  963.   /* Allowing nil is an RMSism */
  964.   struct buffer *real_buf = decode_buffer (buffer, 1);
  965.   real_buf->undo_list = Qt;
  966.   return Qnil;
  967. }
  968.  
  969. DEFUN ("buffer-enable-undo", Fbuffer_enable_undo, Sbuffer_enable_undo,
  970.        0, 1, "",
  971.   "Start keeping undo information for buffer BUFFER.\n\
  972. No argument or nil as argument means do this for the current buffer.")
  973.   (buffer)
  974.      Lisp_Object buffer;
  975. {
  976.   /* Allowing nil is an RMSism */
  977.   struct buffer *real_buf = decode_buffer (buffer, 1);
  978.   if (EQ (real_buf->undo_list, Qt))
  979.     real_buf->undo_list = Qnil;
  980.  
  981.   return Qnil;
  982. }
  983.  
  984. DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 1, 1, "bKill buffer: ",
  985.   "Kill the buffer BUFNAME.\n\
  986. The argument may be a buffer or may be the name of a buffer.\n\
  987. An argument of nil means kill the current buffer.\n\n\
  988. Value is t if the buffer is actually killed, nil if user says no.\n\n\
  989. The value of `kill-buffer-hook' (which may be local to that buffer),\n\
  990. if not void, is a list of functions to be called, with no arguments,\n\
  991. before the buffer is actually killed.  The buffer to be killed is current\n\
  992. when the hook functions are called.\n\
  993. \n\
  994. Any processes that have this buffer as the `process-buffer' are killed\n\
  995. with `delete-process'.")
  996.   (bufname)
  997.      Lisp_Object bufname;
  998. {
  999.   /* This function can GC */
  1000.   Lisp_Object buf;
  1001.   REGISTER struct buffer *b;
  1002.   struct gcpro gcpro1, gcpro2;
  1003.  
  1004.   if (NILP (bufname))
  1005.     buf = Fcurrent_buffer ();
  1006.   else if (BUFFERP (bufname))
  1007.     buf = bufname;
  1008.   else
  1009.     {
  1010.       buf = get_buffer (bufname, 0);
  1011.       if (NILP (buf)) nsberror (bufname);
  1012.     }
  1013.  
  1014.   b = XBUFFER (buf);
  1015.  
  1016.   /* OK to delete an already-deleted buffer. */
  1017.   if (!BUFFER_LIVE_P (b))
  1018.     return Qnil;
  1019.  
  1020.   /* Don't kill the minibuffer now current.  */
  1021.   if (EQ (buf, Vminibuffer_zero))
  1022.     return Qnil;
  1023.  
  1024.   if (EQ (buf, Vecho_area_buffer))
  1025.     return Qnil;
  1026.  
  1027.   /* Query if the buffer is still modified.  */
  1028.   if (INTERACTIVE && !NILP (b->filename)
  1029.       && BUF_MODIFF (b) > b->save_modified)
  1030.     {
  1031.       Lisp_Object killp;
  1032.       GCPRO2 (buf, bufname);
  1033.       killp = call1
  1034.     (Qyes_or_no_p,
  1035.      (emacs_doprnt_string_c
  1036.       ((CONST Bufbyte *) GETTEXT ("Buffer %s modified; kill anyway? "),
  1037.        Qnil, -1, string_data (XSTRING (b->name)))));
  1038.       UNGCPRO;
  1039.       if (NILP (killp))
  1040.     return Qnil;
  1041.       b = XBUFFER (buf);        /* Hypothetical relocating GC. */
  1042.     }
  1043.  
  1044.   /* Run hooks with the buffer to be killed temporarily selected,
  1045.      unless the buffer is already dead (could have been deleted
  1046.      in the question above).
  1047.    */
  1048.   if (BUFFER_LIVE_P (b))
  1049.     {
  1050.       int speccount = specpdl_depth ();
  1051.       Lisp_Object tail = Qnil;
  1052.  
  1053.       GCPRO2 (buf, tail);
  1054.       record_unwind_protect (save_excursion_restore, save_excursion_save ());
  1055.       Fset_buffer (buf);
  1056.  
  1057.       /* First run the query functions; if any query is answered no,
  1058.          don't kill the buffer.  */
  1059.       for (tail = Vkill_buffer_query_functions;
  1060.            !NILP (tail);
  1061.            tail = Fcdr (tail))
  1062.       {
  1063.     if (NILP (call0 (Fcar (tail))))
  1064.         {
  1065.           UNGCPRO;
  1066.       return unbind_to (speccount, Qnil);
  1067.         }
  1068.       }
  1069.  
  1070.       if (!NILP (Vrun_hooks))
  1071.         call1 (Vrun_hooks, Qkill_buffer_hook);
  1072. #ifdef HAVE_X_WINDOWS
  1073.       /* If an X selection was in this buffer, disown it.
  1074.      We could have done this by simply adding this function to the
  1075.      kill-buffer-hook, but the user might mess that up.
  1076.      */
  1077.       if (EQ (Vwindow_system, Qx))
  1078.     call0 (intern ("xselect-kill-buffer-hook"));
  1079.       /* #### generalise me! */
  1080. #endif
  1081.       unbind_to (speccount, Qnil);
  1082.       UNGCPRO;
  1083.       b = XBUFFER (buf);        /* Hypothetical relocating GC. */
  1084.   }
  1085.  
  1086.   /* We have no more questions to ask.  Verify that it is valid
  1087.      to kill the buffer.  This must be done after the questions
  1088.      since anything can happen within yes-or-no-p.  */
  1089.  
  1090.   /* Don't kill the minibuffer now current.  */
  1091.   if (EQ (buf, XWINDOW (minibuf_window)->buffer))
  1092.     return Qnil;
  1093.  
  1094.   /* Might have been deleted during the last question above */
  1095.   if (!BUFFER_LIVE_P (b))
  1096.     return Qnil;
  1097.  
  1098.   /* Make this buffer not be current.
  1099.      In the process, notice if this is the sole visible buffer
  1100.      and give up if so.  */
  1101.   if (b == current_buffer)
  1102.     {
  1103.       Fset_buffer (Fother_buffer (buf, Qnil, Qnil));
  1104.       if (b == current_buffer)
  1105.     return Qnil;
  1106.     }
  1107.  
  1108.   /* Now there is no question: we can kill the buffer.  */
  1109.  
  1110. #ifdef CLASH_DETECTION
  1111.   /* Unlock this buffer's file, if it is locked.  */
  1112.   unlock_buffer (b);
  1113. #endif /* CLASH_DETECTION */
  1114.  
  1115.   {
  1116.     int speccount = specpdl_depth ();
  1117.     specbind (Qinhibit_quit, Qt);
  1118.  
  1119.     kill_buffer_processes (buf);
  1120.  
  1121.     /* #### This is a problem if this buffer is in a dedicated window.
  1122.        Need to undedicate any windows of this buffer first (and delete them?)
  1123.        */
  1124.     Freplace_buffer_in_windows (buf);
  1125.  
  1126.     delete_from_buffer_alist (buf);
  1127.  
  1128.     font_lock_buffer_was_killed (b);
  1129.  
  1130.     /* Delete any auto-save file, if we saved it in this session.  */
  1131.     if (STRINGP (b->auto_save_file_name)
  1132.     && b->auto_save_modified != 0)
  1133.       {
  1134.     if (!NILP (Vdelete_auto_save_files) &&
  1135.         b->save_modified < b->auto_save_modified)
  1136.       unlink ((char *) string_data (XSTRING (b->auto_save_file_name)));
  1137.       }
  1138.  
  1139.     /* Unchain all markers of this buffer
  1140.        and leave them pointing nowhere.  */
  1141.     {
  1142.       REGISTER struct Lisp_Marker *m, *next;
  1143.       for (m = b->markers; m; m = next)
  1144.     {
  1145.       m->buffer = 0;
  1146.       next = marker_next (m);
  1147.       marker_next (m) = 0;
  1148.     }
  1149.       b->markers = 0;
  1150.     }
  1151.     b->name = Qnil;
  1152.     uninit_buffer_text (b);
  1153.     b->undo_list = Qnil;
  1154.     uninit_buffer_extents (b);
  1155.     unbind_to (speccount, Qnil);
  1156.   }
  1157.   return Qt;
  1158. }
  1159.  
  1160. /* Put the element for buffer BUF at the front of buffer-alist.
  1161.    This is done when a buffer is selected "visibly".
  1162.    It keeps buffer-alist in the order of recency of selection
  1163.    so that other_buffer will return something nice.  */
  1164.  
  1165. void
  1166. record_buffer (Lisp_Object buf)
  1167. {
  1168.   REGISTER Lisp_Object link, prev;
  1169.  
  1170.   prev = Qnil;
  1171.   for (link = Vbuffer_alist; CONSP (link); link = XCDR (link))
  1172.     {
  1173.       if (EQ (XCDR (XCAR (link)), buf))
  1174.     break;
  1175.       prev = link;
  1176.     }
  1177.   /* Effectively do Vbuffer_alist = delq_no_quit (link, Vbuffer_alist) */
  1178.   if (NILP (prev))
  1179.     Vbuffer_alist = XCDR (Vbuffer_alist);
  1180.   else
  1181.     XCDR (prev) = XCDR (XCDR (prev));
  1182.   XCDR (link) = Vbuffer_alist;
  1183.   Vbuffer_alist = link;
  1184.  
  1185.   /* That was the global one.  Now do the same thing for the
  1186.      per-frame buffer-alist. */
  1187.   prev = Qnil;
  1188.   for (link = selected_frame ()->buffer_alist; CONSP (link);
  1189.        link = XCDR (link))
  1190.     {
  1191.       if (EQ (XCDR (XCAR (link)), buf))
  1192.     break;
  1193.       prev = link;
  1194.     }
  1195.   /* Effectively do f->buffer_alist = delq_no_quit (link, f->buffer_alist) */
  1196.   if (NILP (prev))
  1197.     selected_frame ()->buffer_alist =
  1198.       XCDR (selected_frame ()->buffer_alist);
  1199.   else
  1200.     XCDR (prev) = XCDR (XCDR (prev));
  1201.   XCDR (link) = selected_frame ()->buffer_alist;
  1202.   selected_frame ()->buffer_alist = link;
  1203. }
  1204.  
  1205. DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, "BSwitch to buffer: ",
  1206.   "Select buffer BUFNAME in the current window.\n\
  1207. BUFNAME may be a buffer or a buffer name.\n\
  1208. Optional second arg NORECORD non-nil means\n\
  1209. do not put this buffer at the front of the list of recently selected ones.\n\
  1210. \n\
  1211. WARNING: This is NOT the way to work on another buffer temporarily\n\
  1212. within a Lisp program!  Use `set-buffer' instead.  That avoids messing with\n\
  1213. the window-buffer correspondences.")
  1214.   (bufname, norecord)
  1215.      Lisp_Object bufname, norecord;
  1216. {
  1217.   /* This function can GC */
  1218.   Lisp_Object buf;
  1219.   Lisp_Object tem;
  1220.  
  1221. #ifdef I18N3
  1222.   /* #### Doc string should indicate that the buffer name will get
  1223.      translated. */
  1224. #endif
  1225.   if (EQ (minibuf_window, Fselected_window (Qnil)))
  1226.     error ("Cannot switch buffers in minibuffer window");
  1227.   tem = Fwindow_dedicated_p (Fselected_window (Qnil));
  1228.   if (!NILP (tem))
  1229.     error ("Cannot switch buffers in a dedicated window");
  1230.  
  1231.   if (NILP (bufname))
  1232.     buf = Fother_buffer (Fcurrent_buffer (), Qnil, Qnil);
  1233.   else
  1234.     buf = Fget_buffer_create (bufname);
  1235.   Fset_buffer (buf);
  1236.   if (NILP (norecord))
  1237.     record_buffer (buf);
  1238.  
  1239.   Fset_window_buffer (EQ (Fselected_window (Qnil), minibuf_window)
  1240.               ? Fnext_window (minibuf_window, Qnil, Qnil, Qnil)
  1241.               : Fselected_window (Qnil),
  1242.               buf);
  1243.  
  1244.   return buf;
  1245. }
  1246.  
  1247. DEFUN ("pop-to-buffer", Fpop_to_buffer, Spop_to_buffer, 1, 3, 0,
  1248.   "Select buffer BUFNAME in some window, preferably a different one.\n\
  1249. If BUFNAME is nil, then some other buffer is chosen.\n\
  1250. If `pop-up-windows' is non-nil, windows can be split to do this.\n\
  1251. If optional second arg NOT-THIS-WINDOW-P is non-nil, insist on finding\n\
  1252. another window even if BUFNAME is already visible in the selected window.\n\
  1253. If optional third arg is non-nil, it is the frame to pop to this\n\
  1254. buffer on.")
  1255.   (bufname, not_this_window_p, on_frame)
  1256.      Lisp_Object bufname, not_this_window_p, on_frame;
  1257. {
  1258.   /* This function can GC */
  1259. #ifdef I18N3
  1260.   /* #### Doc string should indicate that the buffer name will get
  1261.      translated. */
  1262. #endif
  1263.   Lisp_Object buf, window, frame;
  1264.   if (NILP (bufname))
  1265.     buf = Fother_buffer (Fcurrent_buffer (), Qnil, Qnil);
  1266.   else
  1267.     buf = Fget_buffer_create (bufname);
  1268.   Fset_buffer (buf);
  1269.   window = Fdisplay_buffer (buf, not_this_window_p, on_frame);
  1270.   frame = Fwindow_frame (window);
  1271.   /* if the display-buffer hook decided to show this buffer in another
  1272.      frame, then select that frame. */
  1273.   if (!EQ (frame, Fselected_frame (Qnil)))
  1274.     Fselect_frame (frame);
  1275.   record_buffer (buf);
  1276.   Fselect_window (window);
  1277.   return buf;
  1278. }
  1279.  
  1280. DEFUN ("current-buffer", Fcurrent_buffer, Scurrent_buffer, 0, 0, 0,
  1281.   "Return the current buffer as a Lisp object.")
  1282.   ()
  1283. {
  1284.   Lisp_Object buf;
  1285.   XSETBUFFER (buf, current_buffer);
  1286.   return buf;
  1287. }
  1288.  
  1289. /* Set the current buffer to b */
  1290.  
  1291. void
  1292. set_buffer_internal (struct buffer *b)
  1293. {
  1294.   REGISTER struct buffer *old_buf;
  1295.   REGISTER Lisp_Object tail;
  1296.  
  1297.   if (current_buffer == b)
  1298.     return;
  1299.  
  1300.   INVALIDATE_PIXEL_TO_GLYPH_CACHE;
  1301.  
  1302.   old_buf = current_buffer;
  1303.   current_buffer = b;
  1304.   invalidate_current_column ();   /* invalidate indentation cache */
  1305.  
  1306. #ifdef HAVE_FEP
  1307.   if (!noninteractive && initialized)
  1308.     {
  1309.       extern Lisp_Object Ffep_force_on (), Ffep_force_off (), Ffep_get_mode ();
  1310.  
  1311.       old_buf->fep_mode = Ffep_get_mode ();
  1312.       
  1313.       if (!NILP (current_buffer->fep_mode))
  1314.     Ffep_force_on ();
  1315.       else
  1316.     Ffep_force_off ();
  1317.   }
  1318. #endif
  1319.  
  1320.   /* Look down buffer's list of local Lisp variables
  1321.      to find and update any that forward into C variables. */
  1322.  
  1323.   LIST_LOOP (tail, b->local_var_alist)
  1324.     {
  1325.       Lisp_Object sym = XCAR (XCAR (tail));
  1326.       Lisp_Object valcontents = XSYMBOL (sym)->value;
  1327.       if (SYMBOL_VALUE_MAGIC_P (valcontents))
  1328.     {
  1329.       /* Just reference the variable
  1330.          to cause it to become set for this buffer.  */
  1331.       (void) find_symbol_value (sym);
  1332.     }
  1333.     }
  1334.  
  1335.   /* Do the same with any others that were local to the previous buffer */
  1336.  
  1337.   if (old_buf)
  1338.     {
  1339.       for (tail = old_buf->local_var_alist; 
  1340.            !NILP (tail);
  1341.            tail = XCDR (tail))
  1342.     {
  1343.       Lisp_Object sym = XCAR (XCAR (tail));
  1344.       Lisp_Object valcontents = XSYMBOL (sym)->value;
  1345.  
  1346.       if (SYMBOL_VALUE_MAGIC_P (valcontents))
  1347.         {
  1348.           /* Just reference the variable
  1349.          to cause it to become set for this buffer.  */
  1350.           (void) find_symbol_value (sym);
  1351.         }
  1352.     }
  1353.     }
  1354. }
  1355.  
  1356. DEFUN ("set-buffer", Fset_buffer, Sset_buffer, 1, 1, 0,
  1357.   "Make the buffer BUFNAME current for editing operations.\n\
  1358. BUFNAME may be a buffer or the name of an existing buffer.\n\
  1359. See also `save-excursion' when you want to make a buffer current temporarily.\n\
  1360. This function does not display the buffer, so its effect ends\n\
  1361. when the current command terminates.\n\
  1362. Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently.")
  1363.   (bufname)
  1364.      Lisp_Object bufname;
  1365. {
  1366.   Lisp_Object buffer;
  1367.   buffer = get_buffer (bufname, 0);
  1368.   if (NILP (buffer))
  1369.     error ("Selecting deleted buffer");
  1370.   set_buffer_internal (XBUFFER (buffer));
  1371.   return buffer;
  1372. }
  1373.  
  1374.  
  1375. DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only,
  1376.                    Sbarf_if_buffer_read_only, 0, 3, 0,
  1377.   "Signal a `buffer-read-only' error if the buffer is read-only.\n\
  1378. Optional argument BUFFER defaults to the current buffer.\n\
  1379. \n\
  1380. If optional argument START is non-nil, all extents in the buffer\n\
  1381. which overlap that part of the buffer are checked to ensure none has a\n\
  1382. `read-only' property. (Extents that lie completely within the range,\n\
  1383. however, are not checked.) END defaults to the value of START.\n\
  1384. \n\
  1385. If START and END are equal, the range checked is [START, END] (i.e.\n\
  1386. closed on both ends); otherwise, the range checked is (START, END)\n\
  1387. (open on both ends), except that extents that lie completely within\n\
  1388. [START, END] are not checked.  See `extent-in-region-p' for a fuller\n\
  1389. discussion.")
  1390.   (buffer, start, end)
  1391.   Lisp_Object buffer, start, end;
  1392. {
  1393.   struct buffer *b = decode_buffer (buffer, 0);
  1394.   Bufpos s, e;
  1395.  
  1396.   if (NILP (start))
  1397.     s = e = -1;
  1398.   else
  1399.     {
  1400.       if (NILP (end))
  1401.     end = start;
  1402.       get_bufrange (b, start, end, &s, &e, 0);
  1403.     }
  1404.   barf_if_buffer_read_only (b, s, e);
  1405.  
  1406.   return (Qnil);
  1407. }
  1408.  
  1409. static void
  1410. bury_buffer_1 (Lisp_Object buffer, Lisp_Object before,
  1411.            Lisp_Object *buffer_alist)
  1412. {
  1413.   Lisp_Object aelt = rassq_no_quit (buffer, *buffer_alist);
  1414.   Lisp_Object link = memq_no_quit (aelt, *buffer_alist);
  1415.   Lisp_Object iter, before_before;
  1416.  
  1417.   *buffer_alist = delq_no_quit (aelt, *buffer_alist);
  1418.   for (before_before = Qnil, iter = *buffer_alist;
  1419.        !NILP (iter) && !EQ (XCDR (XCAR (iter)), before);
  1420.        before_before = iter, iter = XCDR (iter))
  1421.     ;
  1422.   XCDR (link) = iter;
  1423.   if (!NILP (before_before))
  1424.     XCDR (before_before) = link;
  1425.   else
  1426.     *buffer_alist = link;
  1427. }
  1428.  
  1429. DEFUN ("bury-buffer", Fbury_buffer, Sbury_buffer, 0, 2, "",
  1430.   "Put BUFFER at the end of the list of all buffers.\n\
  1431. There it is the least likely candidate for `other-buffer' to return;\n\
  1432. thus, the least likely buffer for \\[switch-to-buffer] to select by default.\n\
  1433. If BUFFER is nil or omitted, bury the current buffer.\n\
  1434. Also, if BUFFER is nil or omitted, remove the current buffer from the\n\
  1435. selected window if it is displayed there.\n\
  1436. If BEFORE is non-nil, it specifies a buffer before which BUFFER\n\
  1437. will be placed, instead of being placed at the end.")
  1438.   (buffer, before)
  1439.      Lisp_Object buffer, before;
  1440. {
  1441.   /* This function can GC */
  1442.   struct buffer *buf = decode_buffer (buffer, 1);
  1443.   /* If we're burying the current buffer, unshow it.  */
  1444.   /* Note that the behavior of (bury-buffer nil) and
  1445.      (bury-buffer (current-buffer)) is not the same.
  1446.      This is illogical but is historical.  Changing it
  1447.      breaks mh-e and TeX and such packages. */
  1448.   if (NILP (buffer))
  1449.     Fswitch_to_buffer (Fother_buffer (Fcurrent_buffer (), Qnil, Qnil), Qnil);
  1450.   XSETBUFFER (buffer, buf);
  1451.  
  1452.   if (!NILP (before))
  1453.     before = get_buffer (before, 1);
  1454.  
  1455.   if (EQ (before, buffer))
  1456.     error ("Cannot place a buffer before itself");
  1457.  
  1458.   bury_buffer_1 (buffer, before, &Vbuffer_alist);
  1459.   bury_buffer_1 (buffer, before, &selected_frame ()->buffer_alist);
  1460.  
  1461.   return Qnil;
  1462. }
  1463.  
  1464.  
  1465. DEFUN ("erase-buffer", Ferase_buffer, Serase_buffer, 0, 1, "*",
  1466.   "Delete the entire contents of the BUFFER.\n\
  1467. Any clipping restriction in effect (see `narrow-to-region') is removed,\n\
  1468. so the buffer is truly empty after this.\n\
  1469. BUFFER defaults to the current buffer if omitted.")
  1470.      (buffer)
  1471.      Lisp_Object buffer;
  1472. {
  1473.   /* This function can GC */
  1474.   struct buffer *b = decode_buffer (buffer, 1);
  1475.   /* #### yuck yuck yuck.  This is gross.  The old echo-area code,
  1476.      however, was the only place that called erase_buffer() with a
  1477.      non-zero NO_CLIP argument.
  1478.  
  1479.      Someone needs to fix up the redisplay code so it is smarter
  1480.      about this, so that the NO_CLIP junk isn't necessary. */
  1481.   int no_clip = (b == XBUFFER (Vecho_area_buffer));
  1482.  
  1483.   INVALIDATE_PIXEL_TO_GLYPH_CACHE;
  1484.  
  1485.   widen_buffer (b, no_clip);
  1486.   buffer_delete_range (b, BUF_BEG (b), BUF_Z (b), 0);
  1487.   b->last_window_start = 1;
  1488.  
  1489.   /* Prevent warnings, or suspension of auto saving, that would happen
  1490.      if future size is less than past size.  Use of erase-buffer
  1491.      implies that the future text is not really related to the past text.  */
  1492.   b->save_length = Qzero;
  1493.  
  1494.   zmacs_region_stays = 0;
  1495.   return Qnil;
  1496. }
  1497.  
  1498.  
  1499.  
  1500. DEFUN ("kill-all-local-variables", Fkill_all_local_variables, Skill_all_local_variables,
  1501.   0, 0, 0,
  1502.   "Switch to Fundamental mode by killing current buffer's local variables.\n\
  1503. Most local variable bindings are eliminated so that the default values\n\
  1504. become effective once more.  Also, the syntax table is set from\n\
  1505. `standard-syntax-table', the local keymap is set to nil,\n\
  1506. and the abbrev table from `fundamental-mode-abbrev-table'.\n\
  1507. This function also forces redisplay of the modeline.\n\
  1508. \n\
  1509. Every function to select a new major mode starts by\n\
  1510. calling this function.\n\n\
  1511. As a special exception, local variables whose names have\n\
  1512. a non-nil `permanent-local' property are not eliminated by this function.\n\
  1513. \n\
  1514. The first thing this function does is run\n\
  1515. the normal hook `change-major-mode-hook'.")
  1516.   ()
  1517. {
  1518.   /* This function can GC */
  1519.   if (!NILP (Vrun_hooks))
  1520.   {
  1521.     call1 (Vrun_hooks, Qchange_major_mode_hook);
  1522.   }
  1523.  
  1524.   reset_buffer_local_variables (current_buffer);
  1525.  
  1526.   kill_buffer_local_variables (current_buffer);
  1527.  
  1528.   /* Force modeline redisplay.  Useful here because all major mode
  1529.      commands call this function.  */
  1530.   MARK_MODELINE_CHANGED;
  1531.  
  1532.   return Qnil;
  1533. }
  1534.  
  1535. void
  1536. syms_of_buffer (void)
  1537. {
  1538.   defsymbol (&Qbuffer_live_p, "buffer-live-p");
  1539.   defsymbol (&Qbuffer_or_string_p, "buffer-or-string-p");
  1540.   defsymbol (&Qmode_class, "mode-class");
  1541.   defsymbol (&Qrename_auto_save_file, "rename-auto-save-file");
  1542.   defsymbol (&Qkill_buffer_hook, "kill-buffer-hook");
  1543.   defsymbol (&Qpermanent_local, "permanent-local");
  1544.  
  1545.   defsymbol (&Qfirst_change_hook, "first-change-hook");
  1546.   defsymbol (&Qbefore_change_functions, "before-change-functions");
  1547.   defsymbol (&Qafter_change_functions, "after-change-functions");
  1548.  
  1549.   /* #### Obsolete, for compatibility */
  1550.   defsymbol (&Qbefore_change_function, "before-change-function");
  1551.   defsymbol (&Qafter_change_function, "after-change-function");
  1552.  
  1553.   defsymbol (&Qbuffer_file_name, "buffer-file-name");
  1554.   defsymbol (&Qbuffer_undo_list, "buffer-undo-list");
  1555.   defsymbol (&Qdefault_directory, "default-directory");
  1556.  
  1557.   defsymbol (&Qget_file_buffer, "get-file-buffer");
  1558.   defsymbol (&Qchange_major_mode_hook, "change-major-mode-hook");
  1559.  
  1560.   defsymbol (&Qfundamental_mode, "fundamental-mode");
  1561.  
  1562.   defsubr (&Sbufferp);
  1563.   defsubr (&Sbuffer_live_p);
  1564.   defsubr (&Sbuffer_list);
  1565.   defsubr (&Sdecode_buffer);
  1566.   defsubr (&Sget_buffer);
  1567.   defsubr (&Sget_file_buffer);
  1568.   defsubr (&Sget_buffer_create);
  1569.  
  1570.   defsubr (&Sgenerate_new_buffer_name);
  1571.   defsubr (&Sbuffer_name);
  1572.   defsubr (&Sbuffer_file_name);
  1573.   defsubr (&Sbuffer_local_variables);
  1574.   defsubr (&Sbuffer_dedicated_frame);
  1575.   defsubr (&Sset_buffer_dedicated_frame);
  1576.   defsubr (&Sbuffer_modified_p);
  1577.   defsubr (&Sset_buffer_modified_p);
  1578.   defsubr (&Sbuffer_modified_tick);
  1579.   defsubr (&Srename_buffer);
  1580.   defsubr (&Sother_buffer);
  1581.   defsubr (&Sbuffer_disable_undo);
  1582.   defsubr (&Sbuffer_enable_undo);
  1583.   defsubr (&Skill_buffer);
  1584.   defsubr (&Serase_buffer);
  1585.   defsubr (&Sswitch_to_buffer);
  1586.   defsubr (&Spop_to_buffer);
  1587.   defsubr (&Scurrent_buffer);
  1588.   defsubr (&Sset_buffer);
  1589.   defsubr (&Sbarf_if_buffer_read_only);
  1590.   defsubr (&Sbury_buffer);
  1591.   defsubr (&Skill_all_local_variables);
  1592.  
  1593.   deferror (&Qprotected_field, "protected-field",
  1594.         "Attempt to modify a protected field", 1);
  1595. }
  1596.  
  1597. /* initialize the buffer routines */
  1598. void
  1599. vars_of_buffer (void)
  1600. {
  1601.   /* This function can GC */
  1602.   staticpro (&QSFundamental);
  1603.   staticpro (&QSscratch);
  1604.   staticpro (&Vbuffer_alist);
  1605.  
  1606.   QSFundamental = Fpurecopy (build_string ("Fundamental"));
  1607.   QSscratch = Fpurecopy (build_string (DEFER_GETTEXT ("*scratch*")));
  1608.  
  1609.   Vbuffer_alist = Qnil;
  1610.   current_buffer = 0;
  1611.  
  1612.   DEFVAR_LISP ("change-major-mode-hook", &Vchange_major_mode_hook,
  1613.     "List of hooks to be run before killing local variables in a buffer.\n\
  1614. This should be used by by any mode that temporarily alters the contents or\n\
  1615. the read-only state of the buffer.  See also `kill-all-local-variables'.");
  1616.   Vchange_major_mode_hook = Qnil;
  1617.  
  1618.   DEFVAR_BOOL ("find-file-compare-truenames", &find_file_compare_truenames,
  1619.     "If this is true, then the find-file command will check the truenames\n\
  1620. of all visited files when deciding whether a given file is already in\n\
  1621. a buffer, instead of just the buffer-file-name.  This means that if you\n\
  1622. attempt to visit another file which is a symbolic-link to a file which is\n\
  1623. already in a buffer, the existing buffer will be found instead of a newly-\n\
  1624. created one.  This works if any component of the pathname (including a non-\n\
  1625. terminal component) is a symbolic link as well, but doesn't work with hard\n\
  1626. links (nothing does).\n\
  1627. \n\
  1628. See also the variable find-file-use-truenames.");
  1629.   find_file_compare_truenames = 0;
  1630.  
  1631.   DEFVAR_BOOL ("find-file-use-truenames", &find_file_use_truenames,
  1632.     "If this is true, then a buffer's visited file-name will always be\n\
  1633. chased back to the real file; it will never be a symbolic link, and there\n\
  1634. will never be a symbolic link anywhere in its directory path.\n\
  1635. That is, the buffer-file-name and buffer-file-truename will be equal.\n\
  1636. This doesn't work with hard links.\n\
  1637. \n\
  1638. See also the variable find-file-compare-truenames.");
  1639.   find_file_use_truenames = 0;
  1640.  
  1641.   DEFVAR_BOOL ("find-file-visit-truename", &find_file_use_truenames,
  1642.     "An alias for `find-file-use-truenames'.\n\
  1643. This variable is present for compatibility with FSF Emacs.");
  1644.  
  1645.   DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions,
  1646.            "List of functions to call before each text change.\n\
  1647. Two arguments are passed to each function: the positions of\n\
  1648. the beginning and end of the range of old text to be changed.\n\
  1649. \(For an insertion, the beginning and end are at the same place.)\n\
  1650. No information is given about the length of the text after the change.\n\
  1651. \n\
  1652. Buffer changes made while executing the `before-change-functions'\n\
  1653. don't call any before-change or after-change functions.");
  1654.   Vbefore_change_functions = Qnil;
  1655.  
  1656.   /* FSF Emacs has the following additional doc at the end of
  1657.      before-change-functions and after-change-functions:
  1658.  
  1659. That's because these variables are temporarily set to nil.\n\
  1660. As a result, a hook function cannot straightforwardly alter the value of\n\
  1661. these variables.  See the Emacs Lisp manual for a way of\n\
  1662. accomplishing an equivalent result by using other variables.
  1663.  
  1664.      But this doesn't apply under XEmacs because things are
  1665.      handled better. */
  1666.  
  1667.   DEFVAR_LISP ("after-change-functions", &Vafter_change_functions,
  1668.            "List of functions to call after each text change.\n\
  1669. Three arguments are passed to each function: the positions of\n\
  1670. the beginning and end of the range of changed text,\n\
  1671. and the length of the pre-change text replaced by that range.\n\
  1672. \(For an insertion, the pre-change length is zero;\n\
  1673. for a deletion, that length is the number of characters deleted,\n\
  1674. and the post-change beginning and end are at the same place.)\n\
  1675. \n\
  1676. Buffer changes made while executing `after-change-functions'\n\
  1677. don't call any before-change or after-change functions.");
  1678.   Vafter_change_functions = Qnil;
  1679.  
  1680.   DEFVAR_LISP ("before-change-function", &Vbefore_change_function,
  1681.            ""); /* obsoleteness will be documented */
  1682.   Vbefore_change_function = Qnil;
  1683.  
  1684.   DEFVAR_LISP ("after-change-function", &Vafter_change_function,
  1685.            ""); /* obsoleteness will be documented */
  1686.   Vafter_change_function = Qnil;
  1687.  
  1688.   DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook,
  1689.   "A list of functions to call before changing a buffer which is unmodified.\n\
  1690. The functions are run using the `run-hooks' function.");
  1691.   Vfirst_change_hook = Qnil;
  1692.  
  1693. #if 0 /* FSFmacs */
  1694.   xxDEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode,
  1695.     "*Non-nil means deactivate the mark when the buffer contents change.");
  1696.   Vtransient_mark_mode = Qnil;
  1697. #endif
  1698.  
  1699.   DEFVAR_INT ("undo-threshold", &undo_threshold,
  1700.     "Keep no more undo information once it exceeds this size.\n\
  1701. This threshold is applied when garbage collection happens.\n\
  1702. The size is counted as the number of bytes occupied,\n\
  1703. which includes both saved text and other data.");
  1704.   undo_threshold = 20000;
  1705.  
  1706.   DEFVAR_INT ("undo-high-threshold", &undo_high_threshold,
  1707.     "Don't keep more than this much size of undo information.\n\
  1708. A command which pushes past this size is itself forgotten.\n\
  1709. This threshold is applied when garbage collection happens.\n\
  1710. The size is counted as the number of bytes occupied,\n\
  1711. which includes both saved text and other data.");
  1712.   undo_high_threshold = 30000;
  1713.  
  1714.   DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only,
  1715.     "*Non-nil means disregard read-only status of buffers or characters.\n\
  1716. If the value is t, disregard `buffer-read-only' and all `read-only'\n\
  1717. text properties.  If the value is a list, disregard `buffer-read-only'\n\
  1718. and disregard a `read-only' text property if the property value\n\
  1719. is a member of the list.");
  1720.   Vinhibit_read_only = Qnil;
  1721.  
  1722.   DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions,
  1723.     "List of functions called with no args to query before killing a buffer.");
  1724.   Vkill_buffer_query_functions = Qnil;
  1725.  
  1726.   DEFVAR_LISP ("delete-auto-save-files", &Vdelete_auto_save_files,
  1727.   "*Non-nil means delete auto-save file when a buffer is saved or killed.");
  1728.   Vdelete_auto_save_files = Qt;
  1729. }
  1730.  
  1731. /* DOC is ignored because it is snagged and recorded externally 
  1732.  *  by make-docfile */
  1733. /* Renamed from DEFVAR_PER_BUFFER because FSFmacs D_P_B takes
  1734.  *  a bogus extra arg, which confuses an otherwise identical make-docfile.c */
  1735. /* Declaring this stuff as const produces 'Cannot reinitialize' messages
  1736.    from SunPro C's fix-and-continue feature (a way neato feature that
  1737.    makes debugging unbelievably more bearable) */
  1738. #define DEFVAR_BUFFER_LOCAL(lname, field_name, doc)            \
  1739.  do { static CONST_IF_NOT_DEBUG struct symbol_value_forward I_hate_C    \
  1740.        = { { { { lrecord_symbol_value_forward },            \
  1741.                (void *) &(buffer_local_flags.field_name), 69 },        \
  1742.              SYMVAL_CURRENT_BUFFER_FORWARD }, 0 };            \
  1743.       defvar_buffer_local ((lname), &I_hate_C);                \
  1744.  } while (0)
  1745.  
  1746. #define DEFVAR_BUFFER_LOCAL_MAGIC(lname, field_name, doc, magicfun)    \
  1747.  do { static CONST_IF_NOT_DEBUG struct symbol_value_forward I_hate_C    \
  1748.        = { { { { lrecord_symbol_value_forward },            \
  1749.                (void *) &(buffer_local_flags.field_name), 69 },        \
  1750.              SYMVAL_CURRENT_BUFFER_FORWARD }, magicfun };        \
  1751.       defvar_buffer_local ((lname), &I_hate_C);                \
  1752.  } while (0)
  1753.  
  1754. static void
  1755. defvar_buffer_local (CONST char *namestring, 
  1756.                      CONST struct symbol_value_forward *m)
  1757. {
  1758.   int offset = ((char *)symbol_value_forward_forward (m)
  1759.                 - (char *)&buffer_local_flags);
  1760.  
  1761.   defvar_mumble (namestring, m, sizeof (*m));
  1762.  
  1763.   *((Lisp_Object *)(offset + (char *)XBUFFER (Vbuffer_local_symbols))) 
  1764.     = intern (namestring);
  1765. }
  1766.  
  1767. /* DOC is ignored because it is snagged and recorded externally 
  1768.  *  by make-docfile */
  1769. #define DEFVAR_BUFFER_DEFAULTS(lname, field_name, doc)            \
  1770.  do { static CONST_IF_NOT_DEBUG struct symbol_value_forward I_hate_C    \
  1771.        = { { { { lrecord_symbol_value_forward },            \
  1772.                (void *) &(buffer_local_flags.field_name), 69 },        \
  1773.              SYMVAL_DEFAULT_BUFFER_FORWARD }, 0 };            \
  1774.       defvar_mumble ((lname), &I_hate_C, sizeof (I_hate_C));        \
  1775.  } while (0)
  1776.  
  1777. #define DEFVAR_BUFFER_DEFAULTS_MAGIC(lname, field_name, doc, magicfun)    \
  1778.  do { static CONST_IF_NOT_DEBUG struct symbol_value_forward I_hate_C    \
  1779.        = { { { { lrecord_symbol_value_forward },            \
  1780.                (void *) &(buffer_local_flags.field_name), 69 },        \
  1781.              SYMVAL_DEFAULT_BUFFER_FORWARD }, magicfun };        \
  1782.       defvar_mumble ((lname), &I_hate_C, sizeof (I_hate_C));        \
  1783.  } while (0)
  1784.  
  1785. static void
  1786. nuke_all_buffer_slots (struct buffer *b, Lisp_Object zap)
  1787. {
  1788.   struct lcrecord_header save;
  1789.  
  1790.   save = b->header;
  1791.   memset (b, 0, sizeof (*b));
  1792.   b->header = save;
  1793.  
  1794. #define MARKED_SLOT(x)    b->x = (zap);
  1795. #include "bufslots.h"
  1796. #undef MARKED_SLOT
  1797. }
  1798.  
  1799. void
  1800. complex_vars_of_buffer (void)
  1801. {
  1802.   /* Make sure all markable slots in buffer_defaults
  1803.      are initialized reasonably, so mark_buffer won't choke.
  1804.    */
  1805.   struct buffer *defs = alloc_lcrecord (sizeof (struct buffer),
  1806.                     lrecord_buffer);
  1807.   struct buffer *syms = alloc_lcrecord (sizeof (struct buffer),
  1808.                     lrecord_buffer);
  1809.  
  1810.   staticpro (&Vbuffer_defaults);
  1811.   staticpro (&Vbuffer_local_symbols);
  1812.   XSETBUFFER (Vbuffer_defaults, defs);
  1813.   XSETBUFFER (Vbuffer_local_symbols, syms);
  1814.   
  1815.   nuke_all_buffer_slots (syms, Qnil);
  1816.   nuke_all_buffer_slots (defs, Qnil);
  1817.   
  1818.   
  1819.   /* Set up the non-nil default values of various buffer slots.
  1820.      Must do these before making the first buffer.
  1821.      */
  1822.   defs->major_mode = Qfundamental_mode;
  1823.   defs->mode_name = QSFundamental;
  1824.   defs->abbrev_table = Qnil;    /* real default setup by Lisp code */
  1825.   defs->downcase_table = Vascii_downcase_table;
  1826.   defs->upcase_table = Vascii_upcase_table;
  1827.   defs->case_canon_table = Vascii_canon_table;
  1828.   defs->case_eqv_table = Vascii_eqv_table;
  1829.   defs->syntax_table = Vstandard_syntax_table;
  1830.   defs->modeline_format = build_string ("%-");  /* reset in loaddefs.el */
  1831.   defs->case_fold_search = Qt;
  1832.   defs->selective_display_ellipses = Qt;
  1833.   defs->tab_width = make_number (8);
  1834.   defs->ctl_arrow = Qt;
  1835.   defs->fill_column = make_number (70);
  1836.   defs->left_margin = Qzero;
  1837.   defs->save_length = Qzero;       /* lisp code wants int-or-nil */
  1838.   defs->modtime = 0;
  1839.   defs->save_modified = 1;
  1840.   defs->auto_save_modified = 0;
  1841.   defs->auto_save_failure_time = -1;
  1842.   
  1843.   {
  1844.     /*  0 means var is always local.  Default used only at creation.
  1845.      * -1 means var is always local.  Default used only at reset and
  1846.      *    creation.
  1847.      * -2 means there's no lisp variable corresponding to this slot
  1848.      *    and the default is only used at creation.
  1849.      * -3 means no Lisp variable.  Default used only at reset and creation.
  1850.      * >0 is mask.  Var is local if ((buffer->local_var_flags & mask) != 0)
  1851.      *              Otherwise default is used.
  1852.      */
  1853.     Lisp_Object always_local_no_default = make_number (0);
  1854.     Lisp_Object always_local_resettable = make_number (-1);
  1855.     Lisp_Object resettable = make_number (-3);
  1856.     
  1857.     /* Assign the local-flags to the slots that have default values.
  1858.        The local flag is a bit that is used in the buffer
  1859.        to say that it has its own local value for the slot.
  1860.        The local flag bits are in the local_var_flags slot of the
  1861.        buffer.  */
  1862.     
  1863.     nuke_all_buffer_slots (&buffer_local_flags, make_number (-2));
  1864.     buffer_local_flags.filename = always_local_no_default;
  1865.     buffer_local_flags.truename = always_local_no_default;
  1866.     buffer_local_flags.directory = always_local_no_default;
  1867.     buffer_local_flags.backed_up = always_local_no_default;
  1868.     buffer_local_flags.save_length = always_local_no_default;
  1869.     buffer_local_flags.auto_save_file_name = always_local_no_default;
  1870.     buffer_local_flags.read_only = always_local_no_default;
  1871.     
  1872.     buffer_local_flags.major_mode = always_local_resettable;
  1873.     buffer_local_flags.mode_name = always_local_resettable;
  1874.     buffer_local_flags.undo_list = always_local_no_default;
  1875. #if 0 /* FSFmacs */
  1876.     buffer_local_flags.mark_active = always_local_resettable;
  1877. #endif
  1878.     
  1879.     buffer_local_flags.keymap = resettable;
  1880.     buffer_local_flags.downcase_table = resettable;
  1881.     buffer_local_flags.upcase_table = resettable;
  1882.     buffer_local_flags.case_canon_table = resettable;
  1883.     buffer_local_flags.case_eqv_table = resettable;
  1884.     buffer_local_flags.syntax_table = resettable;
  1885.     
  1886.     buffer_local_flags.modeline_format = make_number (1);
  1887.     buffer_local_flags.abbrev_mode = make_number (2);
  1888.     buffer_local_flags.overwrite_mode = make_number (4);
  1889.     buffer_local_flags.case_fold_search = make_number (8);
  1890.     buffer_local_flags.auto_fill_function = make_number (0x10);
  1891.     buffer_local_flags.selective_display = make_number (0x20);
  1892.     buffer_local_flags.selective_display_ellipses = make_number (0x40);
  1893.     buffer_local_flags.tab_width = make_number (0x80);
  1894.     buffer_local_flags.truncate_lines = make_number (0x100);
  1895.     buffer_local_flags.ctl_arrow = make_number (0x200);
  1896.     buffer_local_flags.fill_column = make_number (0x400);
  1897.     buffer_local_flags.left_margin = make_number (0x800);
  1898.     buffer_local_flags.abbrev_table = make_number (0x1000);
  1899. #ifdef MSDOS
  1900.     buffer_local_flags.buffer_file_type = make_number (0x2000);
  1901. #endif
  1902.     
  1903. #ifdef MULE_REGEXP
  1904.     buffer_local_flags.category_table = make_number (0x4000);
  1905. #endif
  1906. #ifdef HAVE_FEP
  1907.     buffer_local_flags.fep_mode = make_number (0x8000);
  1908. #endif
  1909.     /* #### Warning, 0x4000000 (that's six zeroes) is the largest number
  1910.        currently allowable due to the XINT() handling of this value.
  1911.        With some rearrangement you can get 4 more bits. */
  1912.   }
  1913.  
  1914.   DEFVAR_BUFFER_DEFAULTS ("default-modeline-format", modeline_format,
  1915.     "Default value of `modeline-format' for buffers that don't override it.\n\
  1916. This is the same as (default-value 'modeline-format).");
  1917.  
  1918.   DEFVAR_BUFFER_DEFAULTS ("default-abbrev-mode", abbrev_mode,
  1919.     "Default value of `abbrev-mode' for buffers that do not override it.\n\
  1920. This is the same as (default-value 'abbrev-mode).");
  1921.  
  1922.   DEFVAR_BUFFER_DEFAULTS ("default-ctl-arrow", ctl_arrow,
  1923.     "Default value of `ctl-arrow' for buffers that do not override it.\n\
  1924. This is the same as (default-value 'ctl-arrow).");
  1925.  
  1926. #if 0 /* #### make this a specifier! */
  1927.   DEFVAR_BUFFER_DEFAULTS ("default-display-direction", display_direction,
  1928.     "Default display-direction for buffers that do not override it.\n\
  1929. This is the same as (default-value 'display-direction).\n\
  1930. Note: This is not yet implemented.");
  1931. #endif
  1932.  
  1933.   DEFVAR_BUFFER_DEFAULTS ("default-truncate-lines", truncate_lines,
  1934.     "Default value of `truncate-lines' for buffers that do not override it.\n\
  1935. This is the same as (default-value 'truncate-lines).");
  1936.  
  1937.   DEFVAR_BUFFER_DEFAULTS ("default-fill-column", fill_column,
  1938.     "Default value of `fill-column' for buffers that do not override it.\n\
  1939. This is the same as (default-value 'fill-column).");
  1940.  
  1941.   DEFVAR_BUFFER_DEFAULTS ("default-left-margin", left_margin,
  1942.     "Default value of `left-margin' for buffers that do not override it.\n\
  1943. This is the same as (default-value 'left-margin).");
  1944.  
  1945.   DEFVAR_BUFFER_DEFAULTS ("default-tab-width", tab_width,
  1946.     "Default value of `tab-width' for buffers that do not override it.\n\
  1947. This is the same as (default-value 'tab-width).");
  1948.  
  1949.   DEFVAR_BUFFER_DEFAULTS ("default-case-fold-search", case_fold_search,
  1950.     "Default value of `case-fold-search' for buffers that don't override it.\n\
  1951. This is the same as (default-value 'case-fold-search).");
  1952.  
  1953. #ifdef MSDOS
  1954.   DEFVAR_BUFFER_DEFAULTS ("default-buffer-file-type", buffer_file_type,
  1955.     "Default file type for buffers that do not override it.\n\
  1956. This is the same as (default-value 'buffer-file-type).\n\
  1957. The file type is nil for text, t for binary.");
  1958. #endif
  1959.  
  1960.   DEFVAR_BUFFER_LOCAL ("modeline-format", modeline_format,
  1961.     "Template for displaying modeline for current buffer.\n\
  1962. Each buffer has its own value of this variable.\n\
  1963. Value may be a string, a symbol or a list or cons cell.\n\
  1964. For a symbol, its value is used (but it is ignored if t or nil).\n\
  1965.  A string appearing directly as the value of a symbol is processed verbatim\n\
  1966.  in that the %-constructs below are not recognized.\n\
  1967. For a list whose car is a symbol, the symbol's value is taken,\n\
  1968.  and if that is non-nil, the cadr of the list is processed recursively.\n\
  1969.  Otherwise, the caddr of the list (if there is one) is processed.\n\
  1970. For a list whose car is a string or list, each element is processed\n\
  1971.  recursively and the results are effectively concatenated.\n\
  1972. For a list whose car is an integer, the cdr of the list is processed\n\
  1973.   and padded (if the number is positive) or truncated (if negative)\n\
  1974.   to the width specified by that number.\n\
  1975. A string is printed verbatim in the modeline except for %-constructs:\n\
  1976.   (%-constructs are allowed when the string is the entire modeline-format\n\
  1977.    or when it is found in a cons-cell or a list)\n\
  1978.   %b -- print buffer name.      %c -- print the current column number.\n\
  1979.   %f -- print visited file name.\n\
  1980.   %* -- print %, * or hyphen.   %+ -- print *, % or hyphen.\n\
  1981.     % means buffer is read-only and * means it is modified.\n\
  1982.     For a modified read-only buffer, %* gives % and %+ gives *.\n\
  1983.   %s -- print process status.   %l -- print the current line number.\n\
  1984.   %S -- print name of selected frame (only meaningful under X Windows).\n\
  1985.   %p -- print percent of buffer above top of window, or Top, Bot or All.\n\
  1986.   %P -- print percent of buffer above bottom of window, perhaps plus Top,\n\
  1987.         or print Bottom or All.\n\
  1988.   %n -- print Narrow if appropriate.\n\
  1989.   %t -- Under MS-DOS, print T if files is text, B if binary.\n\
  1990.   %[ -- print one [ for each recursive editing level.  %] similar.\n\
  1991.   %% -- print %.                %- -- print infinitely many dashes.\n\
  1992. Decimal digits after the % specify field width to which to pad.");
  1993.  
  1994.   DEFVAR_BUFFER_DEFAULTS ("default-major-mode", major_mode,
  1995.     "*Major mode for new buffers.  Defaults to `fundamental-mode'.\n\
  1996. nil here means use current buffer's major mode.");
  1997.  
  1998.   DEFVAR_BUFFER_DEFAULTS ("fundamental-mode-abbrev-table", abbrev_table,
  1999.     "The abbrev table of mode-specific abbrevs for Fundamental Mode.");
  2000.  
  2001.   DEFVAR_BUFFER_LOCAL ("major-mode", major_mode,
  2002.     "Symbol for current buffer's major mode.");
  2003.  
  2004.   DEFVAR_BUFFER_LOCAL ("mode-name", mode_name,
  2005.     "Pretty name of current buffer's major mode (a string).");
  2006.  
  2007.   DEFVAR_BUFFER_LOCAL ("abbrev-mode", abbrev_mode,
  2008.     "Non-nil turns on automatic expansion of abbrevs as they are inserted.\n\
  2009. Automatically becomes buffer-local when set in any fashion.");
  2010.  
  2011.   DEFVAR_BUFFER_LOCAL ("case-fold-search", case_fold_search,
  2012.     "*Non-nil if searches should ignore case.\n\
  2013. Automatically becomes buffer-local when set in any fashion.");
  2014.  
  2015.   DEFVAR_BUFFER_LOCAL ("fill-column", fill_column,
  2016.     "*Column beyond which automatic line-wrapping should happen.\n\
  2017. Automatically becomes buffer-local when set in any fashion.");
  2018.  
  2019.   DEFVAR_BUFFER_LOCAL ("left-margin", left_margin,
  2020.     "*Column for the default indent-line-function to indent to.\n\
  2021. Linefeed indents to this column in Fundamental mode.\n\
  2022. Automatically becomes buffer-local when set in any fashion.\n\
  2023. Do not confuse this with the specifier `left-margin-width';\n\
  2024. that controls the size of a margin that is displayed outside\n\
  2025. of the text area.");
  2026.  
  2027.   DEFVAR_BUFFER_LOCAL ("tab-width", tab_width,
  2028.     "*Distance between tab stops (for display of tab characters), in columns.\n\
  2029. Automatically becomes buffer-local when set in any fashion.");
  2030.  
  2031.   DEFVAR_BUFFER_LOCAL ("ctl-arrow", ctl_arrow,
  2032.     "*Non-nil means display control chars with uparrow.\n\
  2033. Nil means use backslash and octal digits.\n\
  2034. An integer means characters >= ctl-arrow are assumed to be printable, and\n\
  2035. will be displayed as a single glyph.\n\
  2036. Any other value is the same as 160 - the code SPC with the high bit on.\n\
  2037. \n\
  2038. The interpretation of this variable is likely to change in the future.\n\
  2039. \n\
  2040. Automatically becomes buffer-local when set in any fashion.\n\
  2041. This variable does not apply to characters whose display is specified\n\
  2042. in the current display table (if there is one).");
  2043.  
  2044. #if 0 /* #### Make this a specifier! */
  2045.   DEFVAR_BUFFER_LOCAL ("display-direction", display_direction,
  2046.     "*Non-nil means lines in the buffer are displayed right to left.\n\
  2047. Nil means left to right. (Not yet implemented.)");
  2048. #endif
  2049.  
  2050.   DEFVAR_BUFFER_LOCAL_MAGIC ("truncate-lines", truncate_lines,
  2051.     "*Non-nil means do not display continuation lines;\n\
  2052. give each line of text one frame line.\n\
  2053. Automatically becomes buffer-local when set in any fashion.\n\
  2054. \n\
  2055. Note that this is overridden by the variable\n\
  2056. `truncate-partial-width-windows' if that variable is non-nil\n\
  2057. and this buffer is not full-frame width.",
  2058.                  redisplay_variable_changed);
  2059.  
  2060.   DEFVAR_BUFFER_LOCAL ("default-directory", directory,
  2061.     "Name of default directory of current buffer.  Should end with slash.\n\
  2062. Each buffer has its own value of this variable.");
  2063.  
  2064. #ifdef HAVE_FEP
  2065.   DEFVAR_BUFFER_LOCAL ("fep-mode", fep_mode,
  2066.     "*Document me.");
  2067. #endif
  2068.  
  2069. #ifdef MSDOS
  2070.   DEFVAR_BUFFER_LOCAL ("buffer-file-type", buffer_file_type,
  2071.     "*If visited file is text, nil; otherwise, t.");
  2072. #endif
  2073.  
  2074.   DEFVAR_BUFFER_LOCAL ("auto-fill-function", auto_fill_function,
  2075.     "Function called (if non-nil) to perform auto-fill.\n\
  2076. It is called after self-inserting a space at a column beyond `fill-column'.\n\
  2077. Each buffer has its own value of this variable.\n\
  2078. NOTE: This variable is not an ordinary hook;\n\
  2079. It may not be a list of functions.");
  2080.  
  2081.   DEFVAR_BUFFER_LOCAL ("buffer-file-name", filename,
  2082.     "Name of file visited in current buffer, or nil if not visiting a file.\n\
  2083. Each buffer has its own value of this variable.");
  2084.  
  2085.   DEFVAR_BUFFER_LOCAL ("buffer-file-truename", truename,
  2086.     "The real name of the file visited in the current buffer, \n\
  2087. or nil if not visiting a file.  This is the result of passing \n\
  2088. buffer-file-name to the `truename' function.  Every buffer has \n\
  2089. its own value of this variable.  This variable is automatically \n\
  2090. maintained by the functions that change the file name associated \n\
  2091. with a buffer.");
  2092.  
  2093.   DEFVAR_BUFFER_LOCAL ("buffer-auto-save-file-name", auto_save_file_name,
  2094.     "Name of file for auto-saving current buffer,\n\
  2095. or nil if buffer should not be auto-saved.\n\
  2096. Each buffer has its own value of this variable.");
  2097.  
  2098.   DEFVAR_BUFFER_LOCAL ("buffer-read-only", read_only,
  2099.     "Non-nil if this buffer is read-only.\n\
  2100. Each buffer has its own value of this variable.");
  2101.  
  2102.   DEFVAR_BUFFER_LOCAL ("buffer-backed-up", backed_up,
  2103.     "Non-nil if this buffer's file has been backed up.\n\
  2104. Backing up is done before the first time the file is saved.\n\
  2105. Each buffer has its own value of this variable.");
  2106.  
  2107.   DEFVAR_BUFFER_LOCAL ("buffer-saved-size", save_length,
  2108.     "Length of current buffer when last read in, saved or auto-saved.\n\
  2109. 0 initially.\n\
  2110. Each buffer has its own value of this variable.");
  2111.  
  2112.   DEFVAR_BUFFER_LOCAL ("selective-display", selective_display,
  2113.     "Non-nil enables selective display:\n\
  2114. Integer N as value means display only lines\n\
  2115.  that start with less than n columns of space.\n\
  2116. A value of t means, after a ^M, all the rest of the line is invisible.\n\
  2117.  Then ^M's in the file are written into files as newlines.\n\n\
  2118. Automatically becomes buffer-local when set in any fashion.");
  2119.  
  2120. #ifndef old
  2121.   DEFVAR_BUFFER_LOCAL ("selective-display-ellipses", selective_display_ellipses,
  2122.     "t means display ... on previous line when a line is invisible.\n\
  2123. Automatically becomes buffer-local when set in any fashion.");
  2124. #endif
  2125.  
  2126.   DEFVAR_BUFFER_LOCAL ("local-abbrev-table", abbrev_table,
  2127.     "Local (mode-specific) abbrev table of current buffer.");
  2128.  
  2129.   DEFVAR_BUFFER_LOCAL ("overwrite-mode", overwrite_mode,
  2130.     "Non-nil if self-insertion should replace existing text.\n\
  2131. If non-nil and not `overwrite-mode-binary', self-insertion still\n\
  2132. inserts at the end of a line, and inserts when point is before a tab,\n\
  2133. until the tab is filled in.\n\
  2134. If `overwrite-mode-binary', self-insertion replaces newlines and tabs too.\n\
  2135. Automatically becomes buffer-local when set in any fashion.");
  2136.  
  2137. #if 0 /* FSFmacs */
  2138.   /* Adds the following to the doc string for buffer-undo-list:
  2139.  
  2140. An entry (nil PROP VAL BEG . END) indicates that a text property
  2141. was modified between BEG and END.  PROP is the property name,
  2142. and VAL is the old value.
  2143. */
  2144. #endif
  2145.  
  2146.   DEFVAR_BUFFER_LOCAL ("buffer-undo-list", undo_list,
  2147.     "List of undo entries in current buffer.\n\
  2148. Recent changes come first; older changes follow newer.\n\
  2149. \n\
  2150. An entry (START . END) represents an insertion which begins at\n\
  2151. position START and ends at position END.\n\
  2152. \n\
  2153. An entry (TEXT . POSITION) represents the deletion of the string TEXT\n\
  2154. from (abs POSITION).  If POSITION is positive, point was at the front\n\
  2155. of the text being deleted; if negative, point was at the end.\n\
  2156. \n\
  2157. An entry (t HIGHWORD LOWWORD) indicates that the buffer had been\n\
  2158. previously unmodified.  HIGHWORD and LOWWORD are the high and low\n\
  2159. 16-bit words of the buffer's modification count at the time.  If the\n\
  2160. modification count of the most recent save is different, this entry is\n\
  2161. obsolete.\n\
  2162. \n\
  2163. An entry of the form POSITION indicates that point was at the buffer\n\
  2164. location given by the integer.  Undoing an entry of this form places\n\
  2165. point at POSITION.\n\
  2166. \n\
  2167. nil marks undo boundaries.  The undo command treats the changes\n\
  2168. between two undo boundaries as a single step to be undone.\n\
  2169. \n\
  2170. If the value of the variable is t, undo information is not recorded.");
  2171.  
  2172. #if 0 /* FSFmacs */
  2173.   xxDEFVAR_BUFFER_LOCAL ("mark-active", mark_active, 
  2174.     "Non-nil means the mark and region are currently active in this buffer.\n\
  2175. Automatically local in all buffers.");
  2176. #endif
  2177.  
  2178.   /* Check for DEFVAR_BUFFER_LOCAL without initializing the corresponding
  2179.      slot of buffer_local_flags and vice-versa.  Must be done after all
  2180.      DEFVAR_BUFFER_LOCAL() calls. */
  2181. #define MARKED_SLOT(slot)                    \
  2182.   if ((XINT (buffer_local_flags.slot) != -2 &&            \
  2183.          XINT (buffer_local_flags.slot) != -3)            \
  2184.       != !(NILP (XBUFFER (Vbuffer_local_symbols)->slot)))    \
  2185.   abort ()
  2186. #include "bufslots.h"
  2187. #undef MARKED_SLOT
  2188.  
  2189.   Vprin1_to_string_buffer
  2190.     = Fget_buffer_create (Fpurecopy (build_string (" prin1")));
  2191.   /* Reset Vbuffer_alist again so that the above buf is magically
  2192.      invisible */
  2193.   Vbuffer_alist = Qnil;
  2194.   /* Want no undo records for prin1_to_string_buffer */
  2195.   Fbuffer_disable_undo (Vprin1_to_string_buffer);
  2196.   
  2197.   {
  2198.     Lisp_Object scratch =
  2199.       Fset_buffer (Fget_buffer_create (QSscratch));
  2200.     /* Want no undo records for *scratch* until after Emacs is dumped */
  2201.     Fbuffer_disable_undo (scratch);
  2202.   }
  2203. }
  2204.  
  2205. void
  2206. init_buffer (void)
  2207. {
  2208.   /* This function can GC */
  2209.   char buf[MAXPATHLEN+1];
  2210.  
  2211.   buf[0] = 0;
  2212.  
  2213.   Fset_buffer (Fget_buffer_create (QSscratch));
  2214.  
  2215. #ifndef VMS /* Need filename-syntax-independent absolute-pathname-p ! */
  2216.   {
  2217.     /* If PWD is accurate, use it instead of calling getwd.  This is faster
  2218.        when PWD is right, and may avoid a fatal error.  */
  2219.     struct stat dotstat, pwdstat;
  2220.     char *pwd = getenv ("PWD");
  2221.  
  2222.     if (pwd && pwd[0] == '/'
  2223.         && stat (pwd, &pwdstat) == 0
  2224.         && stat (".", &dotstat) == 0
  2225.         && dotstat.st_ino == pwdstat.st_ino
  2226.         && dotstat.st_dev == pwdstat.st_dev
  2227.         && (int) strlen (pwd) < MAXPATHLEN)
  2228.       strcpy (buf, pwd);
  2229.   }
  2230. #endif /* not VMS */
  2231.   if (buf[0] == 0)
  2232.     {
  2233.       /* PWD env var didn't work for us */
  2234.       if (getwd (buf) == 0)
  2235.     fatal ("`getwd' failed: %s.", buf);
  2236.     }
  2237.  
  2238. #ifndef VMS
  2239.   /* Maybe this should really use some standard subroutine
  2240.      whose definition is filename syntax dependent.  */
  2241.   if (buf[strlen (buf) - 1] != '/')
  2242.     strcat (buf, "/");
  2243. #endif /* not VMS */
  2244.   current_buffer->directory = build_string (buf);
  2245.  
  2246. #if 0 /* FSFmacs */
  2247.   /* #### is this correct? */
  2248.   temp = get_minibuffer (0);
  2249.   XBUFFER (temp)->directory = current_buffer->directory;
  2250. #endif
  2251. }
  2252.